﻿using BCCommon;
using BCCommon.TMS.Insured;
using BCDto.TMS.InsuredConfig;
using BCService.TMS.InsuredConfig;
using BCTMSRESTful.Configs;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace BCTMSRESTful.Controllers.Management.TMS.InsuredConfig
{
    /// <summary>
    /// 保价配置
    /// </summary>
    [Route("api/v1/sim/[controller]")]
    [ApiExplorerSettings(GroupName = "TMSAdmin")]
    public class InsuredConfigController : ManagementBaseController
    {
        private readonly IInsuredConfigService insuredConfigService;

        public InsuredConfigController(IInsuredConfigService insuredConfigService)
        {
            this.insuredConfigService = insuredConfigService;
        }

        /// <summary>
        /// 添加保价配置
        /// </summary>
        /// <param name="requestDto">保价配置添加信息</param>
        /// <response code="201">添加保价配置</response>
        /// <returns></returns>
        [HttpPost]
        [ProducesResponseType(typeof(InsuredConfigDto), 201)]
        [Log("添加保价配置")]
        public IActionResult Post([FromBody] InsuredConfigRequestDto requestDto)
        {
            var result = this.insuredConfigService.Add(this.Admin, requestDto);
            return this.Ok(result);
        }

        /// <summary>
        /// 修改保价配置
        /// </summary>
        /// <param name="insuredConfigId">保价配置Id</param>
        /// <param name="requestDto">保价配置添加信息</param>
        /// <response code="200">修改保价配置</response>
        /// <returns></returns>
        [HttpPut("{insured_config_id}")]
        [ProducesResponseType(typeof(InsuredConfigDto), 200)]
        [Log("修改保价配置")]
        public IActionResult Put([FromRoute(Name = "insured_config_id")]int insuredConfigId,
            [FromBody] InsuredConfigRequestDto requestDto)
        {
            var result = this.insuredConfigService.Update(this.Admin, insuredConfigId, requestDto);
            return this.Ok(result);
        }

        /// <summary>
        /// 删除保价配置
        /// </summary>
        /// <param name="insuredConfigId">保价配置Id</param>
        /// <response code="204">删除保价配置</response>
        /// <returns></returns>
        [HttpDelete("{insured_config_id}")]
        [ProducesResponseType(typeof(NoContentResult), 204)]
        [Log("删除保价配置")]
        public IActionResult Delete([FromRoute(Name = "insured_config_id")] int insuredConfigId)
        {
            this.insuredConfigService.Delete(this.Admin, insuredConfigId);
            return NoContent();
        }

        /// <summary>
        /// 获取保价配置
        /// </summary>
        /// <param name="insuredType">保价类型</param>
        /// <param name="vehicleTransportBusinessConfigId">车辆运输业务配置ID</param>
        /// <param name="createStartDate">创建开始日期</param>
        /// <param name="createEndDate">创建结束日期</param>
        /// <param name="pageIndex">页号</param>
        /// <param name="pageSize">每页数据条数</param>
        /// <response code="200">获取保价配置</response>
        /// <returns></returns>
        [HttpGet("[action]")]
        [ProducesResponseType(typeof(PageableList<InsuredConfigViewDto>), 200)]
        public IActionResult Query([FromQuery(Name = "insured_type")] InsuredType? insuredType,
            [FromQuery(Name = "vehicle_transport_business_config_id")] int? vehicleTransportBusinessConfigId,
            [FromQuery(Name = "create_start_date")] DateTime? createStartDate,
            [FromQuery(Name = "create_end_date")] DateTime? createEndDate,
            [FromQuery(Name = "page_index")] int pageIndex = 1,
            [FromQuery(Name = "page_size")] int pageSize = 10)
        {
            var result = this.insuredConfigService.Query(this.Admin, insuredType, vehicleTransportBusinessConfigId, createStartDate, createEndDate, pageIndex, pageSize);
            return this.Ok(result);
        }

        /// <summary>
        /// 获取保价配置列表
        /// </summary>
        /// <param name="insuredType">保价类型</param>
        /// <param name="vehicleTransportBusinessConfigId">车辆运输业务配置ID</param>
        /// <response code="200">获取保价配置列表</response>
        /// <returns></returns>
        [HttpGet("[action]")]
        [ProducesResponseType(typeof(IEnumerable<InsuredConfigViewDto>), 200)]
        public IActionResult List([FromQuery(Name = "insured_type")] InsuredType? insuredType,
            [FromQuery(Name = "vehicle_transport_business_config_id")]int? vehicleTransportBusinessConfigId)
        {
            var result = this.insuredConfigService.GetList(this.Admin, insuredType, vehicleTransportBusinessConfigId);
            return this.Ok(result);
        }
    }
}
